<?php
/** RatingWizard
 * @package schs-cms
 * @subpackage Wizard
 * @author Igor.Barkowsky@gmail.com
 * @copyright 2009
 */
class RatingWizard extends Wizard
{
	var $db,$user;
	var $table = "ratings";
	var $id = "id";
	var $pid = "pid";
	function __construct(MyDB $db,$tablename = '',$pfx = '',$pid = '')
	{
		$this->db = $db;
		$this->user = new SiteUsersWizard($this->db);
		if(strlen($tablename) > 0){$this->table = mysql_real_escape_string($tablename);}
		if(strlen($pfx) > 0){$this->pfx = mysql_real_escape_string($pfx);}
		if(strlen($pid) > 0){$this->pid = $pid;}
	}
	function getAverage($module = '',$obj_id = 0)
	{
		if(strlen($module) > 0 and intval($obj_id) != 0)
		{
			$avg = $this->db->fetch_one("SELECT AVG(grade) FROM $this->table WHERE module = '".mysql_real_escape_string($module)."' AND obj_id = '".intval($obj_id)."'");
			if($avg != false) return $avg[0];
		}
		else return false;
	}
}
/** Структура таблицы рейтинга */
/*
id
module
obj_id
user_id
ip
grade
time
*/
?>